<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="投资人id" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入投资人id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="站点名称" prop="stationName">
        <el-input
          v-model="queryParams.stationName"
          placeholder="请输入站点名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="详细地址" prop="address">-->
<!--        <el-input-->
<!--          v-model="queryParams.address"-->
<!--          placeholder="请输入详细地址"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="原价" prop="originalPrice">-->
<!--        <el-input-->
<!--          v-model="queryParams.originalPrice"-->
<!--          placeholder="请输入原价"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="实际价格" prop="price">-->
<!--        <el-input-->
<!--          v-model="queryParams.price"-->
<!--          placeholder="请输入实际价格"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="停车收费模式  0计时收费 1按次收费2分段收费3封顶收费" prop="parkFee">-->
<!--        <el-input-->
<!--          v-model="queryParams.parkFee"-->
<!--          placeholder="请输入停车收费模式  0计时收费 1按次收费2分段收费3封顶收费"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="是否有休息室 0是 1否" prop="lounge">-->
<!--        <el-input-->
<!--          v-model="queryParams.lounge"-->
<!--          placeholder="请输入是否有休息室 0是 1否"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="是否有卫生间 0是 1否" prop="toilet">-->
<!--        <el-input-->
<!--          v-model="queryParams.toilet"-->
<!--          placeholder="请输入是否有卫生间 0是 1否"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="是否有商场 0是 1否" prop="shoppingMall">-->
<!--        <el-input-->
<!--          v-model="queryParams.shoppingMall"-->
<!--          placeholder="请输入是否有商场 0是 1否"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="是否有洗车场  0是 1否" prop="washCar">-->
<!--        <el-input-->
<!--          v-model="queryParams.washCar"-->
<!--          placeholder="请输入是否有洗车场  0是 1否"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="洗车费用" prop="washFee">-->
<!--        <el-input-->
<!--          v-model="queryParams.washFee"-->
<!--          placeholder="请输入洗车费用"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="营业开始时间" prop="businessStartTime">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.businessStartTime"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择营业开始时间">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="营业结束时间" prop="businessEndTime">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.businessEndTime"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择营业结束时间">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="是否有饮食  0是 1否" prop="diet">-->
<!--        <el-input-->
<!--          v-model="queryParams.diet"-->
<!--          placeholder="请输入是否有饮食  0是 1否"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="经度" prop="longitude">-->
<!--        <el-input-->
<!--          v-model="queryParams.longitude"-->
<!--          placeholder="请输入经度"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="纬度" prop="latitude">-->
<!--        <el-input-->
<!--          v-model="queryParams.latitude"-->
<!--          placeholder="请输入纬度"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['charge:charge_station_info:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['charge:charge_station_info:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['charge:charge_station_info:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['charge:charge_station_info:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="charge_station_infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="80" align="center" />
      <el-table-column label="主键id" align="center" prop="id" />
      <el-table-column label="投资人id" align="center" prop="userId" />
      <el-table-column label="站点名称" align="center" prop="stationName" #default="scope">
        <el-tag type="primary" effect="plain">{{ scope.row.stationName }}</el-tag>
      </el-table-column>
      <el-table-column label="详细地址" align="center" prop="address" #default="scope">
        <el-tag type="info" effect="plain" style="max-width: 200px; white-space: normal; text-align: left;">{{ scope.row.address }}</el-tag>
      </el-table-column>
      <el-table-column label="专用类型" align="center" prop="dedicatedType" #default="scope">
        <el-tag :type="scope.row.dedicatedType === 0 ? 'danger' : 'success'">
          {{ scope.row.dedicatedType === 0 ? '不适合' : '适合' }}
        </el-tag>
      </el-table-column>
      <el-table-column label="充电速度类型" align="center" prop="chargingSpeedType" #default="scope">
        <el-tag :type="getChargingSpeedType(scope.row.chargingSpeedType)">
          {{ getChargingSpeedText(scope.row.chargingSpeedType) }}
        </el-tag>
      </el-table-column>
      <el-table-column label="原价" align="center" prop="originalPrice" #default="scope">
        <el-tag type="warning" effect="plain">¥{{ scope.row.originalPrice }}/度</el-tag>
      </el-table-column>
      <el-table-column label="实际价格" align="center" prop="price" #default="scope">
        <el-tag type="success" effect="plain">¥{{ scope.row.price }}/度</el-tag>
      </el-table-column>
      <el-table-column label="停车收费模式" align="center" prop="parkFee" #default="scope">
        <el-tag :type="getParkFeeType(scope.row.parkFee)">
          {{ getParkFeeText(scope.row.parkFee) }}
        </el-tag>
      </el-table-column>
      <el-table-column label="休息室" align="center" prop="lounge" #default="scope">
        <el-tag :type="scope.row.lounge === 0 ? 'success' : 'info'">
          {{ scope.row.lounge === 0 ? '有' : '无' }}
        </el-tag>
      </el-table-column>
      <el-table-column label="卫生间" align="center" prop="toilet" #default="scope">
        <el-tag :type="scope.row.toilet === 0 ? 'success' : 'info'">
          {{ scope.row.toilet === 0 ? '有' : '无' }}
        </el-tag>
      </el-table-column>
      <el-table-column label="是否有商场" align="center" prop="shoppingMall" #default="scope">
        <el-tag :type="scope.row.shoppingMall === 0 ? 'success' : 'info'">
          {{ scope.row.shoppingMall === 0 ? '有' : '无' }}
        </el-tag>
      </el-table-column>
      <el-table-column label="洗车场" align="center" prop="washCar" #default="scope">
        <el-tag :type="scope.row.washCar === 0 ? 'success' : 'info'">
          {{ scope.row.washCar === 0 ? '有' : '无' }}
        </el-tag>
      </el-table-column>
      <el-table-column label="洗车费用" align="center" prop="washFee" #default="scope">
        <el-tag type="warning" effect="plain">¥{{ scope.row.washFee }}</el-tag>
      </el-table-column>
      <el-table-column label="营业开始时间" align="center" prop="businessStartTime" #default="scope">
        <span>{{ parseTime(scope.row.businessStartTime, '{h}:{i}') }}</span>
      </el-table-column>
      <el-table-column label="营业结束时间" align="center" prop="businessEndTime" #default="scope">
        <span>{{ parseTime(scope.row.businessEndTime, '{h}:{i}') }}</span>
      </el-table-column>
      <el-table-column label="饮食" align="center" prop="diet" #default="scope">
        <el-tag :type="scope.row.diet === 0 ? 'success' : 'info'">
          {{ scope.row.diet === 0 ? '有' : '无' }}
        </el-tag>
      </el-table-column>
      <el-table-column label="经纬度" align="center" #default="scope">
        <el-tag type="info" effect="plain">
          {{ scope.row.longitude }}, {{ scope.row.latitude }}
        </el-tag>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status" #default="scope">
        <el-tag :type="getStatusType(scope.row.status)">
          {{ getStatusText(scope.row.status) }}
        </el-tag>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['charge:charge_station_info:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['charge:charge_station_info:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改充电站对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="投资人id:" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入投资人id" />
        </el-form-item>
        <el-form-item label="站点名称:" prop="stationName">
          <el-input v-model="form.stationName" placeholder="请输入站点名称" />
        </el-form-item>
        <el-form-item label="详细地址:" prop="address">
          <el-input v-model="form.address" placeholder="请输入详细地址" />
        </el-form-item>
        <el-form-item label="专用类型:" prop="dedicatedType">
          <el-input v-model="form.dedicatedType" placeholder="请输入专用类型 0不适合 1适合" />
        </el-form-item>
        <el-form-item label="充电速度:" prop="chargingSpeedType">
          <el-input v-model="form.chargingSpeedType" placeholder="请输入充电速度 0慢充 1快充 2都支持" />
        </el-form-item>
        <el-form-item label="原价:" prop="originalPrice">
          <el-input v-model="form.originalPrice" placeholder="请输入原价" />
        </el-form-item>
        <el-form-item label="实际价格:" prop="price">
          <el-input v-model="form.price" placeholder="请输入实际价格" />
        </el-form-item>
        <el-form-item label="停车收费模式:" prop="parkFee">
          <el-input v-model="form.parkFee" placeholder="请输入停车收费模式  0计时收费 1按次收费2分段收费3封顶收费" />
        </el-form-item>
        <el-form-item label="是否有休息室:" prop="lounge">
          <el-input v-model="form.lounge" placeholder="请输入是否有休息室 0是 1否" />
        </el-form-item>
        <el-form-item label="是否有卫生间:" prop="toilet">
          <el-input v-model="form.toilet" placeholder="请输入是否有卫生间 0是 1否" />
        </el-form-item>
        <el-form-item label="是否有商场:" prop="shoppingMall">
          <el-input v-model="form.shoppingMall" placeholder="请输入是否有商场 0是 1否" />
        </el-form-item>
        <el-form-item label="是否有洗车场:" prop="washCar">
          <el-input v-model="form.washCar" placeholder="请输入是否有洗车场  0是 1否" />
        </el-form-item>
        <el-form-item label="洗车费用:" prop="washFee">
          <el-input v-model="form.washFee" placeholder="请输入洗车费用" />
        </el-form-item>
        <el-form-item label="营业开始时间:" prop="businessStartTime">
          <el-date-picker clearable
            v-model="form.businessStartTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择营业开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="营业结束时间" prop="businessEndTime">
          <el-date-picker clearable
            v-model="form.businessEndTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择营业结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="是否有饮食:" prop="diet">
          <el-input v-model="form.diet" placeholder="请输入是否有饮食  0是 1否" />
        </el-form-item>
        <el-form-item label="经度:" prop="longitude">
          <el-input v-model="form.longitude" placeholder="请输入经度" />
        </el-form-item>
        <el-form-item label="纬度:" prop="latitude">
          <el-input v-model="form.latitude" placeholder="请输入纬度" />
        </el-form-item>
        <el-form-item label="状态:" prop="status">
          <el-input v-model="form.status" placeholder="请输入状态 0空闲中 1使用中 2维护中 3已报废 4调试中" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCharge_station_info, getCharge_station_info, delCharge_station_info, addCharge_station_info, updateCharge_station_info } from "@/api/charge/charge_station_info";

export default {
  name: "Charge_station_info",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 充电站表格数据
      charge_station_infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        stationName: null,
        address: null,
        dedicatedType: null,
        chargingSpeedType: null,
        originalPrice: null,
        price: null,
        parkFee: null,
        lounge: null,
        toilet: null,
        shoppingMall: null,
        washCar: null,
        washFee: null,
        businessStartTime: null,
        businessEndTime: null,
        diet: null,
        longitude: null,
        latitude: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        stationName: [
          { required: true, message: "站点名称不能为空", trigger: "blur" }
        ],
        address: [
          { required: true, message: "详细地址不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询充电站列表 */
    getList() {
      this.loading = true;
      listCharge_station_info(this.queryParams).then(response => {
        this.charge_station_infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        stationName: null,
        address: null,
        dedicatedType: null,
        chargingSpeedType: null,
        originalPrice: null,
        price: null,
        parkFee: null,
        lounge: null,
        toilet: null,
        shoppingMall: null,
        washCar: null,
        washFee: null,
        businessStartTime: null,
        businessEndTime: null,
        diet: null,
        longitude: null,
        latitude: null,
        status: null,
        createTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加充电站";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCharge_station_info(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改充电站";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCharge_station_info(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCharge_station_info(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除充电站编号为"' + ids + '"的数据项？').then(function() {
        return delCharge_station_info(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('charge/charge_station_info/export', {
        ...this.queryParams
      }, `charge_station_info_${new Date().getTime()}.xlsx`)
    },
    /** 获取充电速度类型 */
    getChargingSpeedType(type) {
      const typeMap = {
        0: 'warning',  // 慢充
        1: 'success',  // 快充
        2: 'primary'   // 都支持
      };
      return typeMap[type] || 'info';
    },
    /** 获取充电速度文本 */
    getChargingSpeedText(type) {
      const textMap = {
        0: '慢充',
        1: '快充',
        2: '都支持'
      };
      return textMap[type] || '未知';
    },
    /** 获取停车收费类型 */
    getParkFeeType(type) {
      const typeMap = {
        0: 'info',     // 计时收费
        1: 'primary',  // 按次收费
        2: 'warning',  // 分段收费
        3: 'success'   // 封顶收费
      };
      return typeMap[type] || 'info';
    },
    /** 获取停车收费文本 */
    getParkFeeText(type) {
      const textMap = {
        0: '计时收费',
        1: '按次收费',
        2: '分段收费',
        3: '封顶收费'
      };
      return textMap[type] || '未知';
    },
    /** 获取状态类型 */
    getStatusType(status) {
      const statusMap = {
        0: 'success',  // 正常
        1: 'danger',   // 停用
        2: 'warning'   // 维护中
      };
      return statusMap[status] || 'info';
    },
    /** 获取状态文本 */
    getStatusText(status) {
      const statusMap = {
        0: '正常',
        1: '停用',
        2: '维护中'
      };
      return statusMap[status] || '未知';
    }
  }
};
</script>
